import watermark from '@/util/watermark'
import useSettingsStore from '@/store/modules/settings'

export const useWatermark = () => {
  const settingsStore = useSettingsStore()

  watch(() => settingsStore.app.enableWatermark, val => {
    if (val) {
      loadWatermark()
    } else {
      removeWatermark()
    }
  }, {
    immediate: true
  })

  function loadWatermark(x, y) {
    // 水印更多设置请查看 https://github.com/saucxs/watermark-dom
    watermark.init({
      // watermark_txt: `${userStore.userInfo.userNamePinyinAll}95998`,
      watermark_x: x,
      watermark_y: y
    })
  }

  function removeWatermark() {
    try {
      watermark.remove()
    } catch (err) {
      // 忽略报错
    }
  }

  return {
    loadWatermark,
    removeWatermark
  }
}
